package com.example.myapplication.fragment.fragment2;


import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Toolbar;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.mvp.mvp.view.BaseFragment;
import com.example.myapplication.R;
import com.example.myapplication.a_mvp.contract.MyContract;
import com.example.myapplication.a_mvp.presenter.DaxiaPresenter;
import com.example.myapplication.a_utils.Dag_Mod;
import com.example.myapplication.a_utils.DaggerDag_Com;
import com.example.myapplication.adapter.Daxia_Adapter;
import com.example.myapplication.b_entity.Login_Entity;
import com.example.myapplication.b_entity.Daxia;
import com.example.myapplication.b_entity.Reg_Entity;
import com.jwenfeng.library.pulltorefresh.BaseRefreshListener;
import com.jwenfeng.library.pulltorefresh.PullToRefreshLayout;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class City_Fragment extends BaseFragment<DaxiaPresenter> implements MyContract.MyView {
    private View view;
    private RecyclerView fragmentRec;
    private int index1 = 10,index2 = 1;
    private PullToRefreshLayout pullToRefreshLayout;
    private Daxia_Adapter meizi_adapter;


    @Override
    public int findlayout() {
        return R.layout.city_fragment;
    }

    @Override
    public void initView() {
        fragmentRec = (RecyclerView) findViewById(R.id.fragment_rec);
        pullToRefreshLayout = (PullToRefreshLayout) findViewById(R.id.fragment_pull);
    }

    @Override
    public void initData() {
        DaggerDag_Com.builder().dag_Mod(new Dag_Mod(this)).build().daxia(this);
        mypre.getMeizi(index1,index2);
        pullToRefreshLayout.setRefreshListener(new BaseRefreshListener() {
            @Override
            public void refresh() {

                index1+=10;
                mypre.getMeizi(index1,index2);
                pullToRefreshLayout.finishRefresh();
            }

            @Override
            public void loadMore() {

                index1 = 10;
                ++index2;
                mypre.getMeizi(index1,index2);
                pullToRefreshLayout.finishLoadMore();

            }
        });
    }

    @Override
    public void show_reg(Reg_Entity reg_entity) {

    }

    @Override
    public void show_login(Login_Entity login_entity) {

    }

    @Override
    public void show_daxia(List<Daxia.DataBean> list) {
        meizi_adapter = new Daxia_Adapter(R.layout.item,list);
        fragmentRec.setAdapter(meizi_adapter);
        fragmentRec.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
        meizi_adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                getActivity().startActivity(new Intent(getContext(),City_Activity.class).putExtra("index",position));
            }
        });

    }


}
